import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

// import { h } from 'vue';
import { DictEnum } from '@vben/constants';
// import { VbenIcon } from '@vben/icons';
import { getPopupContainer } from '@vben/utils';

// import { Tag } from 'ant-design-vue';
// import { z } from '#/adapter/form';
import { SensitiveText } from '#/components/text';
import { getDictOptions } from '#/utils/dict';
import { renderDict } from '#/utils/render';

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'name',
    label: '姓名',
  },
  {
    component: 'CompanySearchSelect',
    fieldName: 'companyId',
    label: '公司',
  },
  {
    component: 'Select',
    fieldName: 'departmentIds',
    label: '部门',
    componentProps: {
      mode: 'multiple',
      getPopupContainer,
      options: getDictOptions(DictEnum.AUDIENCE_DEPARTMENT, true),
    },
  },
  {
    component: 'Select',
    fieldName: 'positionIds',
    label: '职位',
    componentProps: {
      mode: 'multiple',
      getPopupContainer,
      options: getDictOptions(DictEnum.AUDIENCE_POSITION, true),
    },
  },
  {
    component: 'Select',
    fieldName: 'year',
    label: '年份',
    componentProps: {
      getPopupContainer,
      options: getDictOptions(DictEnum.EXHIBITION_YEAR, true),
    },
  },
  {
    component: 'RegisterTrackCascader',
    fieldName: 'sourceTrackIds',
    componentProps: {
      multiple: true,
    },
    disabledOnChangeListener: false,
    defaultValue: [],
    label: '所属来源',
  },
  {
    component: 'Select',
    fieldName: 'signStatus',
    label: '签到状态',
    componentProps: {
      getPopupContainer,
      options: getDictOptions(DictEnum.MEETING_SIGN_STATUS, true),
    },
  },
  {
    component: 'Select',
    fieldName: 'auditStatus',
    label: '审核状态',
    componentProps: {
      getPopupContainer,
      options: getDictOptions(DictEnum.MEETING_AUDIT_STATUS, true),
    },
  },
  {
    component: 'Select',
    fieldName: 'role',
    label: '角色',
    componentProps: {
      getPopupContainer,
      options: getDictOptions(DictEnum.MEETING_ENROLL_ROLE, true),
    },
  },
  {
    component: 'RangePicker',
    fieldName: 'createTime',
    label: '登记日期',
  },
  {
    component: 'RangePicker',
    fieldName: 'auditTime',
    label: '审核日期',
  },
];

export const columns: VxeGridProps['columns'] = [
  { type: 'checkbox', width: 60 },
  {
    title: '公司',
    field: 'companyName',
    width: 240,
    slots: { default: 'companyName' },
  },
  {
    title: '姓名',
    field: 'name',
    width: 160,
    slots: { default: 'name' },
  },
  {
    title: '年份',
    field: 'year',
    width: 100,
    slots: {
      default: ({ row }) => {
        return renderDict(row.year, DictEnum.EXHIBITION_YEAR);
      },
    },
    visible: false,
  },
  {
    title: '手机',
    field: 'mobile',
    width: 160,
    slots: {
      default: ({ row }) => {
        return (
          <SensitiveText
            access-page={5}
            employee-id={row.employeeId}
            text={row.mobile}
            type={1}
          />
        );
      },
    },
  },
  {
    title: '部门',
    field: 'departmentId',
    width: 160,
    slots: {
      default: ({ row }) => {
        return renderDict(row.departmentId, DictEnum.AUDIENCE_DEPARTMENT);
      },
    },
  },
  {
    title: '职位',
    field: 'positionId',
    width: 160,
    slots: {
      default: ({ row }) => {
        return renderDict(row.positionId, DictEnum.AUDIENCE_POSITION);
      },
    },
  },
  {
    title: '报名会议名称',
    field: 'meetingName',
    width: 240,
  },
  // {
  //   title: '所在地区',
  //   field: 'countryCode',
  //   width: 200,
  //   slots: {
  //     default: ({ row }) => {
  //       if (row?.countryCode !== '00') {
  //         return <span>{row.countryCode}</span>;
  //       }
  //
  //       if (row?.cityName) {
  //         return (
  //           <span>
  //             {row.provinceName}
  //             {row.cityName}
  //           </span>
  //         );
  //       }
  //
  //       return <span>{row?.provinceName}</span>;
  //     },
  //   },
  // },
  {
    title: '所属来源',
    field: 'sourceTrackName',
    width: 200,
    showOverflow: true,
  },
  {
    title: '报名时间',
    field: 'createTime',
    width: 180,
  },
  {
    title: '签到状态',
    field: 'signStatus',
    width: 130,
    slots: { default: 'signStatus' },
  },
  {
    title: '审核状态',
    field: 'auditStatus',
    width: 130,
    slots: {
      default: ({ row }) => {
        return renderDict(row.auditStatus, DictEnum.MEETING_AUDIT_STATUS);
      },
    },
    visible: false,
  },
  {
    title: '角色',
    field: 'role',
    width: 150,
    slots: {
      default: ({ row }) => {
        return renderDict(row.role, DictEnum.MEETING_ENROLL_ROLE);
      },
    },
    visible: false,
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 150,
  },
];

export const detailsSchema: DetailsModalSchemaGetter = () => [
  {
    label: '姓名',
    fieldName: 'name',
    copy: true,
  },
  {
    label: '公司',
    fieldName: 'companyName',
    copy: true,
  },
  {
    label: '年份',
    fieldName: 'year',
    dictEnum: DictEnum.EXHIBITION_YEAR,
  },
  {
    label: '手机号',
    fieldName: 'mobile',
    slots: {
      default: (info) => {
        return (
          <SensitiveText
            access-page={5}
            employee-id={info.employeeId}
            text={info.mobile}
            type={1}
          />
        );
      },
    },
  },
  {
    label: '部门',
    fieldName: 'departmentId',
    dictEnum: DictEnum.AUDIENCE_DEPARTMENT,
  },
  {
    label: '职位',
    fieldName: 'positionId',
    dictEnum: DictEnum.AUDIENCE_POSITION,
  },
  {
    label: '报名会议名称',
    fieldName: 'meetingName',
    copy: true,
  },
  // {
  //   label: '所在地区',
  //   fieldName: 'countryCode',
  //   span: 2,
  //   copy: (info: any) => {
  //     if (info.countryCode !== '00') {
  //       return `${info.address} ${info.countryName}`;
  //     }
  //
  //     return `${info.countryName}${info.provinceName}${info.cityName}${info.districtName}${info.address}`;
  //   },
  //   slots: {
  //     default: (info) => {
  //       if (info.countryCode !== '00') {
  //         return (
  //           <span>
  //             {info.address} {info.countryName}
  //           </span>
  //         );
  //       }
  //       return (
  //         <span>
  //           {info.countryName}
  //           {info.provinceName}
  //           {info.cityName}
  //           {info.districtName}
  //           {info.address}
  //         </span>
  //       );
  //     },
  //   },
  // },
  {
    label: '所属来源',
    fieldName: 'sourceTrackName',
    copy: true,
  },
  {
    label: '签到状态',
    fieldName: 'signStatus',
    dictEnum: DictEnum.MEETING_SIGN_STATUS,
  },
  {
    label: '审核状态',
    fieldName: 'auditStatus',
    dictEnum: DictEnum.MEETING_AUDIT_STATUS,
  },
  {
    label: '角色',
    fieldName: 'role',
    dictEnum: DictEnum.MEETING_ENROLL_ROLE,
  },
  {
    label: '备注',
    fieldName: 'remark',
  },
];
